home *** CD-ROM | disk | FTP | other *** search
Text File | 1994-04-21 | 5.2 KB | 223 lines | [TEXT/MPS ] |
- //========================================================================================
- //
- // File: PaletteFacet.cpp
- // Release Version: $ 1.0d1 $
- //
- // Author: Henri Lamiraux
- // Creation Date: 3/28/94
- //
- // Copyright: © 1993, 1994 by Apple Computer, Inc., all rights reserved.
- //
- //========================================================================================
-
- #ifndef PALETTEFACET_H
- #include "PaletteFacet.h"
- #endif
-
- #ifndef DRAWPART_H
- #include "DrawPart.h"
- #endif
-
- #ifndef DRAWSELECTION_H
- #include "DrawSelection.h"
- #endif
-
- #ifndef SHAPES_H
- #include "Shapes.h"
- #endif
-
- #ifndef DRAWFRAME_H
- #include "DrawFrame.h"
- #endif
-
- // ----- Framework Includes -----
-
- #ifndef FWMEMMGR_H
- #include <FWMemMgr.h>
- #endif
-
- #ifndef FWUTIL_H
- #include "FWUtil.h"
- #endif
-
- #ifndef FWFRMING_H
- #include "FWFrming.h"
- #endif
-
- // ----- Graphix Includes -----
-
- #ifndef FWINK_H
- #include "FWInk.h"
- #endif
-
- #ifndef FWSTYLE_H
- #include "FWStyle.h"
- #endif
-
- #ifndef FWCOLOR_H
- #include "FWColor.h"
- #endif
-
- // ----- OpenDoc Includes -----
-
- #ifndef _TRNSFORM_
- #include <Trnsform.h>
- #endif
-
- // ----- Macintosh Includes -----
-
- #if defined(FW_BUILD_MAC) && !defined(__EVENTS__)
- #include <Events.h> // GetMouse, StillDown.
- #endif
-
- #if defined(FW_BUILD_MAC) && !defined(__TOOLUTILS__)
- #include <ToolUtils.h> // HiWord etc.
- #endif
-
- #if defined(FW_BUILD_MAC) && !defined(__LIMITS__)
- #include <limits.h>
- #endif
-
- #if defined(FW_BUILD_MAC) && !defined(__STDLIB__)
- #include <StdLib.h> // Abs
- #endif
-
- #if defined(FW_BUILD_MAC) && !defined(__DRAG__)
- #include <Drag.h>
- #endif
-
- #if defined(FW_BUILD_MAC) && !defined(mathRoutinesIncludes)
- #include <math routines.h> // See MoveTransformBy
- #endif
-
- #pragma segment drawpart
-
- //=========================================================================
- // CPaletteFacet
- //=========================================================================
-
- //------------------------------------------------------------------------------
- // CPaletteFacet::CPaletteFacet
- //------------------------------------------------------------------------------
-
- CPaletteFacet::CPaletteFacet() :
- fColorTable(NULL)
- {
- }
-
- //------------------------------------------------------------------------------
- // CPaletteFacet::InitPaletteFacet
- //------------------------------------------------------------------------------
-
- void CPaletteFacet::InitPaletteFacet(XMPFacet* xmpFacet, CDrawPart* drawPart)
- {
- InitFacet(xmpFacet);
- fDrawPart = drawPart;
-
- fColorTable = ::GetCTable(8);
- }
-
- //------------------------------------------------------------------------------
- // CPaletteFacet::~CPaletteFacet
- //------------------------------------------------------------------------------
-
- CPaletteFacet::~CPaletteFacet()
- {
- if (fColorTable)
- ::DisposCTable(fColorTable);
- }
-
- //------------------------------------------------------------------------------
- // CPaletteFacet::Draw
- //------------------------------------------------------------------------------
-
- void CPaletteFacet::Draw(FW_CGraphicContext *gc)
- {
- // ----- Draw the grid -----
- FW_CLineShape line(FW_CPoint(ff(2), ff(2)), FW_CPoint(ff(kPaletteWindowWidth-3), ff(2)));
- for (unsigned short i = 1; i<=9; i++)
- {
- line->Draw(gc);
- line->MoveShape(0, ff(9));
- }
-
- line->SetLineStart(FW_CPoint(ff(2), ff(2)));
- line->SetLineEnd(FW_CPoint(ff(2), ff(kPaletteWindowHeight-3)));
- for (i = 1; i<=33; i++)
- {
- line->Draw(gc);
- line->MoveShape(ff(9), 0);
- }
-
- // ----- Draw each color -----
- FW_CRectShape rect(FW_CRect(ff(3), ff(3), ff(11), ff(11)));
- short colorIndex = 0;
- FW_CColor color;
- FW_CMemoryManager::LockSystemHandle((FW_PlatformHandle)fColorTable);
- for (short j = 0; j<8; j++)
- {
- for (short i = 0; i<32; i++)
- {
- GetColor(colorIndex, &color);
- rect->SetForeColor(color);
- rect->Draw(gc);
- rect->MoveShape(ff(9), ff(0));
- colorIndex++;
- }
-
- rect->MoveShape(ff(-9 * 32), ff(9));
- }
- FW_CMemoryManager::UnlockSystemHandle((FW_PlatformHandle)fColorTable);
- }
-
- //------------------------------------------------------------------------------
- // CPaletteFacet::DoMouseDown
- //------------------------------------------------------------------------------
-
- FW_Boolean CPaletteFacet::DoMouseDown(const FW_CPoint& where, XMPEventData event)
- {
- FW_UNUSED(event);
- FW_UNUSED(where);
-
- short colorIndex = CalcIndex(where);
-
- if (colorIndex>=0)
- {
- FW_CColor color;
- GetColor(colorIndex, &color);
-
- if (::TestOptionKey(event))
- fDrawPart->SetPenColor(color);
- else
- fDrawPart->SetFillColor(color);
- }
-
- return TRUE;
- }
-
- //------------------------------------------------------------------------------
- // CPaletteFacet::GetColor
- //------------------------------------------------------------------------------
-
- void CPaletteFacet::GetColor(short colorIndex, FW_CColor* color) const
- {
- *color = (*fColorTable)->ctTable[colorIndex].rgb;
- }
-
- //------------------------------------------------------------------------------
- // CPaletteFacet::CalcIndex
- //------------------------------------------------------------------------------
-
- short CPaletteFacet::CalcIndex(const FW_CPoint& where) const
- {
- FW_CRect paletteRect(ff(2), ff(2), ff(kPaletteWindowWidth-2), ff(kPaletteWindowHeight-2));
-
- if (paletteRect.Contains(where))
- {
- short x = (FixedToInt(where.x) - 2) / 9;
- short y = (FixedToInt(where.y) - 2) / 9;
- return y * 32 + x;
- }
-
- return -1;
- }